//
//  RemindCell.m
//  liangyi
//
//  Created by 张水 on 17/1/5.
//  Copyright © 2017年 yswh. All rights reserved.
//

#import "RemindCell.h"
#import "AppHeader.h"

@implementation RemindCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

-(void)setModel:(Remind *)model{
    _model = model;
    self.contentLable.text = model.content;
    self.timeLable.text = [NSString timeWithTimeIntervalString:model.createTime];
}


- (void)setupUI{
    self.backgroundColor = [UIColor whiteColor];
    
    self.contentLable = [[UILabel alloc]init];
    [self.contentView addSubview:self.contentLable];
    [self.contentLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.right.equalTo(self.contentView).offset(-20);
        make.top.equalTo(self.contentView).offset(10);
    }];
    self.contentLable.textColor = [UIColor blackColor];
    self.contentLable.textAlignment = NSTextAlignmentLeft;
    self.contentLable.numberOfLines = 0;
    self.contentLable.font = [UIFont systemFontOfSize:18];
    
    self.timeLable = [[UILabel alloc]init];
    [self.contentView addSubview:self.timeLable];
    [self.timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.bottom.equalTo(self.contentView).offset(-5);
    }];
    self.timeLable.textColor = [UIColor ColorWithHex:@"#8a8989"];
    self.timeLable.textAlignment = NSTextAlignmentRight;
    self.timeLable.font = [UIFont systemFontOfSize:10];
    
    UIView *line = [[UIView alloc]init];
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.contentView);
        make.height.equalTo(@1);
    }];
    line.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    
    
}

- (NSString *)timeWithTimeIntervalString:(NSString *)timeString
{
    // 格式化时间
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
    
    // 毫秒值转化为秒
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]/ 1000.0];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
}

@end
